package com.gym.web.controller.lockers.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.gym.common.annotation.Log;
import com.gym.common.enums.BusinessType;
import com.gym.system.lockers.domain.GymLockers;
import com.gym.system.lockers.service.IGymLockersService;
import com.gym.common.core.controller.BaseController;
import com.gym.common.core.domain.AjaxResult;
import com.gym.common.utils.poi.ExcelUtil;
import com.gym.common.core.page.TableDataInfo;

/**
 * 场地管理Controller
 *
 * @author administrator
 * @date 2021-04-11
 */
@Controller
@RequestMapping("/lockers/lockers")
public class GymLockersController extends BaseController {
    private String prefix = "lockers/lockers";

    @Autowired
    private IGymLockersService gymLockersService;

    @RequiresPermissions("lockers:lockers:view")
    @GetMapping()
    public String lockers() {
        return prefix + "/lockers";
    }

    /**
     * 查询场地管理列表
     */
    @RequiresPermissions("lockers:lockers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GymLockers gymLockers) {
        startPage();
        List<GymLockers> list = gymLockersService.selectGymLockersList(gymLockers);
        return getDataTable(list);
    }

    /**
     * 导出场地管理列表
     */
    @RequiresPermissions("lockers:lockers:export")
    @Log(title = "场地管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GymLockers gymLockers) {
        List<GymLockers> list = gymLockersService.selectGymLockersList(gymLockers);
        ExcelUtil<GymLockers> util = new ExcelUtil<GymLockers>(GymLockers.class);
        return util.exportExcel(list, "lockers");
    }

    /**
     * 新增场地管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存场地管理
     */
    @RequiresPermissions("lockers:lockers:add")
    @Log(title = "场地管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GymLockers gymLockers) {
        return toAjax(gymLockersService.insertGymLockers(gymLockers));
    }

    /**
     * 修改场地管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        GymLockers gymLockers = gymLockersService.selectGymLockersById(id);
        mmap.put("gymLockers", gymLockers);
        return prefix + "/edit";
    }

    /**
     * 修改保存场地管理
     */
    @RequiresPermissions("lockers:lockers:edit")
    @Log(title = "场地管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GymLockers gymLockers) {
        return toAjax(gymLockersService.updateGymLockers(gymLockers));
    }

    /**
     * 删除场地管理
     */
    @RequiresPermissions("lockers:lockers:remove")
    @Log(title = "场地管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(gymLockersService.deleteGymLockersByIds(ids));
    }
}
